package com.medicine.mapper;

import com.github.pagehelper.Page;
import com.medicine.annotation.AutoFill;
import com.medicine.entity.Medicine;
import com.medicine.enumeration.OperationType;
import com.medicine.vo.MedicineVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface MedicineMapper {
    

    /**
     * 插入菜品数据
     *
     * @param medicine
     */
    @AutoFill(value = OperationType.INSERT)
    void insert(Medicine medicine);


    /**
     * 根据主键查询菜品
     *
     * @param id
     * @return
     */
    @Select("select * from medicine where id = #{id}")
    Medicine getById(Long id);

    /**
     * 根据主键删除菜品数据
     *
     * @param id
     */
    @Delete("delete from medicine where id = #{id}")
    void deleteById(Long id);

    /**
     * 根据id动态修改菜品数据
     *
     * @param medicine
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(Medicine medicine);

    /**
     * 动态条件查询菜品
     *
     * @param medicine
     * @return
     */
    List<Medicine> list(Medicine medicine);

    /**
     * 根据套餐id查询菜品
     * @param setmealId
     * @return
     */
    @Select("select a.* from medicine a left join setmeal_medicine b on a.id = b.medicine_id where b.setmeal_id = #{setmealId}")
    List<Medicine> getBySetmealId(Long setmealId);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
